package com.project.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.project.bean.RoleBean;
import com.project.service.IRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("role")
public class RoleController {
    @Autowired
    private IRoleService roleService;

    @RequestMapping("findByItem")
    public IPage<RoleBean> findByItem(Integer pageNo){
        return  roleService.findByItem(pageNo);
    }

    @RequestMapping("delRole")
    public String delRole(Integer roleId){
        roleService.delRole(roleId);
        return "success";
    }

    @RequestMapping("addRole")
    public String addRole(RoleBean roleBean,Integer[] gradeIds){
        roleService.addRole(roleBean,gradeIds);
        return "success";
    }

    @RequestMapping("findRoleByRoleName")
    public RoleBean findRoleByRoleName(String roleName){
        return roleService.findRoleByRoleName(roleName);
    }

    @RequestMapping("findById")
    public RoleBean findById(Integer roleId){
        return roleService.findById(roleId);
    }

        @RequestMapping("findAll")
    public List<RoleBean> findAll(){
        return roleService.findAll();
    }

    @RequestMapping("updateRoleGradeById")
    public String updateRoleGradeById(Integer roleId,Integer[] gradeIds){
        roleService.updateRoleGradeById(roleId,gradeIds);
        return "success";
    }
}
